﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using PMSGSC.Common;
using PMSGSC.DAL;
using PMSGSC.BLL;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid.Views.Grid.ViewInfo;
using DevExpress.XtraGrid;

namespace PMSGSC.App
{
    public partial class frmDashBoard : DevExpress.XtraEditors.XtraForm
    {
        public frmDashBoard(frmMain objMain)
        {
            InitializeComponent();
            main = objMain;
            departmentList = Department_BLL.GetAll(frmMain.ship.Ship_ID);
            foreach (Department department in departmentList)
            {
                JobInDepartment wo = new JobInDepartment();
                wo.DepartmentId = department.Department_ID;
                wo.DepartmentName = department.DepartmentName;
                wo.QuantityJob = WorkOrder_BLL.GetAmountOfWorkOrderDue(department);
                dashBoardDataSource.Add(wo);
            }

            certificateType = CertificateType_BLL.GetAll(frmMain.ship.Ship_ID);
            foreach (TypeCertificate ct in certificateType)
            {
                OverDueCertificate certificate = new OverDueCertificate();
                certificate.CertificateTypeId = ct.TypeCertificate_ID;
                certificate.CetificateType = ct.NameType;
                certificate.QuantityCetificate = Certificate_BLL.GetQuantityCertificateDue(ct);
                Certificates.Add(certificate);
            }

            gridControl3.DataSource = dashBoardDataSource;
            gridControl2.DataSource = Certificates;
        }
        frmMain main;
        private List<Department> departmentList;
        private List<JobInDepartment> dashBoardDataSource = new List<JobInDepartment>();
        private List<TypeCertificate> certificateType;
        private List<OverDueCertificate> Certificates = new List<OverDueCertificate>();

        private void gridView1_RowStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs e)
        {
            //  e.Appearance.Options.
        }

        private void gridView3_DoubleClick(object sender, EventArgs e)
        {
            GridView view = (GridView)sender;
            Point pt = view.GridControl.PointToClient(Control.MousePosition);
            DoRowDoubleClick(view, pt);
        }

        private void DoRowDoubleClick(GridView view, Point pt)
        {
            GridHitInfo info = view.CalcHitInfo(pt);

            if (info.InRow || info.InRowCell)
            {
                if (info.RowHandle != GridControl.NewItemRowHandle)
                {
                    JobInDepartment currentItem = ((JobInDepartment)gridView3.GetFocusedRow());
                    if (currentItem != null)
                    {
                        frmWorkOrderDeatails workOrder = new frmWorkOrderDeatails(WorkOrder_BLL.GetWorkOrderOrderDue(currentItem.DepartmentId), main);
                        workOrder.MdiParent = main;
                        workOrder.Show();
                    }
                }

            }

        }


        private void gridView2_DoubleClick(object sender, EventArgs e)
        {
            GridView view = (GridView)sender;
            Point pt = view.GridControl.PointToClient(Control.MousePosition);
            DoRowDoubleClick2(view, pt);
        }
        private void DoRowDoubleClick2(GridView view, Point pt)
        {
            GridHitInfo info = view.CalcHitInfo(pt);

            if (info.InRow || info.InRowCell)
            {
                if (info.RowHandle != GridControl.NewItemRowHandle)
                {
                    OverDueCertificate currentItem = ((OverDueCertificate)gridView2.GetFocusedRow());
                    if (currentItem != null)
                    {
                        frmCertificate certificate = new frmCertificate(Certificate_BLL.GetCertificateOverDueList(currentItem.CertificateTypeId));
                        certificate.MdiParent = main;
                        certificate.Show();
                    }
                }

            }

        }
    }
}